class Solution:
    def longestMountain(self, arr: list) -> int:
        upLens = [0 for _ in range(len(arr))]
        downLens = [0 for _ in range(len(arr))]
        tempLen = 1
        for i in range(1, len(arr)):
            if arr[i-1] < arr[i]:
                tempLen += 1
                upLens[i] += tempLen
            else:
                tempLen = 1

        tempLen = 1
        for i in range(len(arr)-2, -1, -1):
            if arr[i+1] < arr[i]:
                tempLen += 1
                downLens[i] += tempLen
            else:
                tempLen = 1
        maxLen = 0
        for i in range(len(arr)):
            if upLens[i] == 0 or downLens[i] == 0:
                continue
            maxLen = max(maxLen, upLens[i]+downLens[i]-1)
        return maxLen
